package com.hyy.book2.mapper;

import com.hyy.book2.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {

    //Controller层才需要@RequestParam
    //Mapper层可以用MyBatis独有的@Parma("")进行参数绑定，但是需要用#{x.xxx}
    @Insert("insert into book_info(book_name, author, count, price, publish) " +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish})")
    Integer insertBook(BookInfo bookInfo);

    //分页查询
    @Select("SELECT * FROM book_info " +
            "WHERE status !=0 " +
            "ORDER BY id " +
            "LIMIT  #{offset},#{limit}")
    List<BookInfo> queryBookPage(Integer offset,Integer limit);

    //获取书本数量
    @Select("select count(1) from book_info where status !=0")
    Integer getCount();


    //根据图书查询图书信息
    Integer updateBook(BookInfo bookInfo);

    @Select("select * from book_info where id=#{bookId}")
    BookInfo queryBookByID(Integer bookId);

    //批量删除也可以删除一个
    Integer batchDelete(List<Integer> ids);
}
